// Created by Windward Studios - no copyright is claimed. This code can be used in
// any manner by anyone for any reason. There is no copyright of any kind on it. You may
// use it in commercial products. You may change it without sharing those changes.
// We ask that you keep the "created by Windward Studios" in a comment at the top.

using System;
using System.Data;

namespace net.windward.utils.ado.Oracle
{
	/// <summary>
	/// Wrap an IDataReader returned on a SqlServer Execute. All this does is add the GetTimestamp method.
	/// </summary>
	public class WrOracleDataReader : WrDataReader
	{

		/// <summary>
		/// Create a WrDataReader object wrapping an IDataReader.
		/// </summary>
		/// <param name="data">The IDataReader we are wrapping.</param>
		public WrOracleDataReader(IDataReader data)
			: base(data)
		{
		}

		/// <summary>
		/// Read a timestamp field and return it as an Int64.
		/// </summary>
		/// <param name="ordinal">The ordinal of the timestamp column.</param>
		/// <returns>The timestamp with [0] as msw and [1] as lsw.</returns>
		public override long GetTimestamp(int ordinal)
		{
			DateTime dt = reader.GetDateTime(ordinal);
			return dt.Ticks;
		}

		#region Oracle's implementation of these are buggy

		///<summary>
		///Gets the value of the specified column as a Boolean.
		///</summary>
		///
		///<returns>
		///The value of the column.
		///</returns>
		///
		///<param name="ind">The zero-based column ordinal. </param>
		///<exception cref="T:System.IndexOutOfRangeException">The index passed was outside the range of 0 through <see cref="P:System.Data.IDataRecord.FieldCount"></see>. </exception><filterpriority>2</filterpriority>
		public override bool GetBoolean(int ind)
		{
			return (int)reader.GetDecimal(ind) != 0;
		}

		///<summary>
		///Gets the 8-bit unsigned integer value of the specified column.
		///</summary>
		///
		///<returns>
		///The 8-bit unsigned integer value of the specified column.
		///</returns>
		///
		///<param name="ind">The zero-based column ordinal. </param>
		///<exception cref="T:System.IndexOutOfRangeException">The index passed was outside the range of 0 through <see cref="P:System.Data.IDataRecord.FieldCount"></see>. </exception><filterpriority>2</filterpriority>
		public override byte GetByte(int ind)
		{
			return (byte)reader.GetDecimal(ind);
		}

		///<summary>
		///Gets the 16-bit signed integer value of the specified field.
		///</summary>
		///
		///<returns>
		///The 16-bit signed integer value of the specified field.
		///</returns>
		///
		///<param name="ind">The index of the field to find. </param>
		///<exception cref="T:System.IndexOutOfRangeException">The index passed was outside the range of 0 through <see cref="P:System.Data.IDataRecord.FieldCount"></see>. </exception><filterpriority>2</filterpriority>
		public override short GetInt16(int ind)
		{
			return (short)reader.GetDecimal(ind);
		}

		#endregion
	}
}
